package com.jiazhong.basic.pack0316.thread;

import java.util.concurrent.locks.Lock;

public class DemoF {

    private int num = 0;
    private Lock lock ;

    public DemoF(Lock lock) {
        this.lock = lock;
    }

    public void change() {
        String name = Thread.currentThread().getName();
        System.out.println(name + "准备运算");
        lock.lock(); // 上锁
        num = num + 1;
        System.out.println(name + "当前结果是：" + num);
        lock.unlock();
    }
}
